package com.cyzy;

import java.io.*;
import java.net.*;

public class RTSPStreamForwarder {
    public static void main(String[] args) {
        int port = 8085;
        try (ServerSocket serverSocket = new ServerSocket(port)) {
            System.out.println("Server is listening on port " + port);

            while (true) {
                try (Socket clientSocket = serverSocket.accept()) {
                    System.out.println("Client connected");

                    DataInputStream dis = new DataInputStream(clientSocket.getInputStream());
                    DataOutputStream dos = new DataOutputStream(clientSocket.getOutputStream());

                    String message = dis.readUTF();
                    System.out.println("Received from client: " + message);

                    // Echo back the message to the client
                    dos.writeUTF(message);
                    dos.flush();

                    dis.close();
                    dos.close();
                    clientSocket.close();
                } catch (IOException e) {
                    System.out.println("Error handling client: " + e.getMessage());
                }
            }
        } catch (IOException e) {
            System.out.println("Could not listen on port " + port);
            System.out.println(e.getMessage());
        }
    }

}
